package com.air.designmodel.ten;

import org.apache.commons.collections.iterators.EnumerationIterator;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;

/**
 * 适配器模式,将火鸡顶替鸭子
 *
 * @author shent
 */
public class DuckTestDrive {
    public static void main(String[] args) {
        Duck duck = new MallardDuck();
        Turkey turkey = new WildTurkey();
        Duck turkeyAdapter = new TurkeyAdapter(turkey);
        turkeyAdapter.quack();
        turkeyAdapter.fly();
        //利用适配器模式,将迭代器转换成枚举
        ArrayList list = new ArrayList<String>();
        list.add("hello");
        Enumeration iteratorEnumeration = new IteratorEnumeration(list.iterator());
        if (iteratorEnumeration.hasMoreElements()) {
            System.out.println("enum " + iteratorEnumeration.nextElement());
        }

    }
}
